<script>
	import authPages from './common/authPages.js'
	export default {
		onLaunch: function() {
			console.log('App Launch')
			if(!this.$common.isEmpty(this.loginInfo.id)){
				console.log(this.loginInfo,'----7;;loginInfo')
				this.$store.dispatch('getKeMu');
			}
			this.$store.dispatch('getProvider');
			const deviceInfo=uni.getDeviceInfo();
			console.log(deviceInfo,'-----------------------deviceInfo')
			this.$store.commit('set', ['DEVICEINFO',deviceInfo]);
			this.getBarHeight();
			this.addInterceptor();
			console.log(this.$common.generateUUID(),'---10')
			this.$store.commit('set', ['uuid',this.$common.generateUUID()]);
			const keMuIndex=this.$store.state.keMuIndex;
			// #ifdef MP-WEIXIN
			if(this.$common.isEmpty(keMuIndex)){//没选过科目，强制选
				uni.reLaunch({
					url: `/pages/cutDrawer/index`
				})
			}
			// #endif
		},
		computed: {
			loginInfo() {
				return this.$store.state.loginInfo;
			}
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			addInterceptor(){
				let that=this;
				uni.addInterceptor('navigateTo', {
					invoke(e) {
						const token = uni.getStorageSync('token');
						console.log(token,'----token')
						if (!token && authPages.includes(e.url.split('?')[0])) {
							uni.showToast({title: '请先绑定手机号',icon: 'none'});
							if(that.$store.state.PROVIDER!=='weixin'){
								uni.reLaunch({ url: '/pagesB/login/login' })
							}
							return false
						}
				  }
				})
			},
			getBarHeight(){
				const systemInfo = uni.getSystemInfoSync();
				const statusBarHeight = systemInfo.statusBarHeight; // 状态栏高度
				let menuButtonInfo = null;
				let titleBarHeight = null;
				let titleVerticalPosition = null;
				// #ifdef MP-WEIXIN
				menuButtonInfo = wx.getMenuButtonBoundingClientRect(); // 胶囊按钮信息
				// #endif
				// 计算标题栏总高度（状态栏高度 + 标题栏高度）
				// 对于微信小程序，标题栏高度可按公式计算:cite[8]:cite[9]
				// #ifdef MP-WEIXIN
				titleBarHeight = (menuButtonInfo.top - statusBarHeight) * 2 + menuButtonInfo.height;
				const customNavBarHeight = statusBarHeight + titleBarHeight; // 整个自定义导航栏的总高度
				// #endif
				
				// 对于非微信小程序平台（如H5、App），标题栏高度可自定义一个值（例如48px）:cite[1]
				// #ifndef MP-WEIXIN
				const customNavBarHeight = statusBarHeight + 44; // 48px是一个常见的标题栏高度示例:cite[1]
				// #endif
				
				// 计算自定义标题内容垂直居中时的 top 位置（微信小程序需与胶囊按钮对齐）:cite[6]:cite[7]:cite[10]
				// #ifdef MP-WEIXIN
				titleVerticalPosition = menuButtonInfo.top; // 使用胶囊按钮的top值
				// #endif
				// 其他平台可以自行设定，通常为状态栏高度 + (标题栏高度 - 内容自身高度) / 2
				this.$store.commit('set', ['barInfo',{customNavBarHeight, statusBarHeight, titleBarHeight, titleVerticalPosition}]);
			}
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import "@/static/font/iconfont.css";
	@import "@/common/styles/base.scss";
</style>
